﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ventas.Data.Entities;

namespace Ventas.Data.Mappings
{
    public class ProductMap : EntityTypeConfiguration<Product>
    {
        public ProductMap()
        { 
            //Name of the table
            ToTable("Products");
            //pk
            HasKey(t => t.Id);
            //Property
            Property(t => t.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            Property(t => t.Codigo).IsRequired();
            //RelationShip
            HasRequired(t => t.Category)
                .WithMany(c => c.Products)
                .HasForeignKey(t => t.CategoryId)
                .WillCascadeOnDelete(false);

        }
    }
}
